package com.wanghengzhi.girlfriend.rbac.module.account;

import com.wanghengzhi.girlfriend.rbac.core.Call;
import com.wanghengzhi.girlfriend.rbac.core.PageWrapper;
import com.wanghengzhi.girlfriend.rbac.module.account.dto.AccountDTO;
import com.wanghengzhi.girlfriend.rbac.module.account.dto.AccountInputDTO;
import com.wanghengzhi.girlfriend.rbac.module.account.dto.AccountPageVO;
import com.wanghengzhi.girlfriend.rbac.module.validator.AddValidator;
import com.wanghengzhi.girlfriend.rbac.module.validator.UpdateValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * 账号
 * @author 王潇
 * @since 2021.6.17
 */
@SuppressWarnings("unused")
@RestController
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PostMapping(value = "/account",  produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Call.RT> add(@RequestBody @Validated(value = AddValidator.class) AccountInputDTO accountInputDTO) {
        Call add = accountService.add(accountInputDTO);
        return new ResponseEntity<>(add.response(), HttpStatus.OK);
    }

    @PutMapping(value = "/account",  produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Call.RT> updateAccount(@RequestBody @Validated(value = UpdateValidator.class)
                                                          AccountInputDTO accountInputDTO) {
        Call updateAccount = accountService.updateAccount(accountInputDTO);
        return new ResponseEntity<>(updateAccount.response(), HttpStatus.OK);
    }

    @GetMapping(value = "/accounts")
    public ResponseEntity<PageWrapper<AccountDTO>> page(@Validated AccountPageVO vo) {
        PageWrapper<AccountDTO> pw = accountService.page(vo.getPage(), vo.getSize(), vo.getAccount());
        return new ResponseEntity<>(pw, HttpStatus.OK);
    }

}
